import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type UserProfileType } from "./profile";

const ACCOUNT_BASE_URL = "/api";

export const AccountAPI = {
  getUserAccountList: (params: AccountListQuery) => {
    return request.get<any, ListResponse<AccountItemType>>(
      `${ACCOUNT_BASE_URL}/internal/UserAccount/`,
      { params }
    );
  },
  getUserAccountDetail: (id: number) => {
    return request.get(`${ACCOUNT_BASE_URL}/internal/UserAccount/${id}/`);
  },
  createUserAccount: (data: Partial<AccountForm>) => {
    return request.post(`${ACCOUNT_BASE_URL}/internal/UserAccount/`, data);
  },
  updateUserAccount: (data: Partial<AccountForm>) => {
    return request.put(`${ACCOUNT_BASE_URL}/internal/UserAccount/${data.id}/`, data);
  },
  deleteUserAccount: (id: number) => {
    return request.delete(`${ACCOUNT_BASE_URL}/internal/UserAccount/${id}/`);
  },
};

export type AccountListQuery = {} & ListQuery;

/**
 * @description 充值订单状态
 * @property {string} income - 入账
 * @property {string} outgoing - 支出
 */
export type AccountType = "income" | "outgoing";

export type AccountItemType = {
  id: number;
  account: UserProfileType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  type: AccountType;
  amount: string;
  remark: string;
};

export type AccountForm = {
  id?: number;
  account: string;
  type: AccountType;
  amount: string;
  remark: string;
};

export default AccountAPI;
